package com.fjp.heartguard.ui.message.adapter

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.fjp.heartguard.R
import com.fjp.heartguard.app.data.bean.Message
import com.fjp.heartguard.app.ext.setAdapterAnimation
import com.fjp.heartguard.app.util.SettingUtil


class MessageAdapter(data: ArrayList<Message>, var clickItem: (item: Message) -> Unit) : BaseQuickAdapter<Message, BaseViewHolder>(R.layout.item_message, data) {
    init {
        setAdapterAnimation(SettingUtil.getListMode())
    }

    override fun convert(holder: BaseViewHolder, item: Message) {
        if (item.is_read == 1) {
            holder.setBackgroundResource(R.id.iconIv, R.drawable.message_item_icon_readed)
        } else {
            holder.setBackgroundResource(R.id.iconIv, R.drawable.message_item_icon_normal)
        }
        if (holder.absoluteAdapterPosition == data.size - 1) {
            holder.setVisible(R.id.bottomLine, false)
        }
        holder.setText(R.id.titleTv, item.title)
        holder.setText(R.id.contentTv, item.content)
        holder.setText(R.id.timeTv, item.created_at)
        holder.itemView.setOnClickListener {
            clickItem.invoke(item)
        }
    }

}


